/**
 * 作者：陈文斌 on 2019/1/7.
 * 邮箱：chen_wennbin@163.com
 * 版本：v1.0
 */

import 'package:flutter/material.dart';
import 'package:crm/constant/constant.dart';
import 'package:crm/model/ClientManager/client_info_model.dart';
import 'package:crm/model/ClientManager/contact_info_model.dart';
import 'package:crm/model/ClientManager/principal_info_model.dart';
import 'package:crm/view/Tile/list_tile_normal.dart';
import 'package:crm/view/Tile/text_expansion_tile.dart';
import 'package:crm/page/ClientManager/client_info_page.dart';
import 'package:crm/page/ClientManager/potential_client_info_page.dart';

class ClientManagerTileSection extends StatelessWidget {
  final ClientInfoModel client;

  ClientManagerTileSection({
    Key key,
    @required this.client,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    List<ContactInfoModel> _contacts =
        client.contacts ?? List<ContactInfoModel>();
    List<PrincipalInfoModel> _principals =
        client.principals ?? List<PrincipalInfoModel>();

    TextStyle _titleStyle = TextStyle(
      color: AppColors.TextColor,
      fontSize: AppFontSizes.Font13,
      fontFamily: AppFontFamilies.PingFangSC,
      fontWeight: FontWeight.w500,
    );
    TextStyle _contactInfoTextStyle = TextStyle(
      color: AppColors.DetailTextColor,
      fontSize: 11,
      fontFamily: AppFontFamilies.PingFangSC,
      fontWeight: FontWeight.w500,
    );

    Widget _divider = Container(
      color: AppColors.LineColor,
      height: 0.5,
      padding: EdgeInsets.only(left: 16),
    );

    return Column(
      children: <Widget>[
        ListTileNormal(
          title: Text(
            '查看资料',
            style: _titleStyle,
          ),
          trailing: const Icon(Icons.expand_more),
          onTap: () {
            if (client.customerType == 0) {
              Navigator.push(
                context,
                MaterialPageRoute(
                  builder: (context) => ClientInfoPage(clientInfo: client),
                ),
              );
            } else {
              Navigator.push(
                context,
                MaterialPageRoute(
                  builder: (context) => PotentialClientInfoPage(clientInfo: client),
                ),
              );
            }
          },
          contentPadding: EdgeInsets.only(right: 16),
          arrowVisible: true,
          dividerVisible: true,
        ),
        _divider,
        TextExpansionTile(
          title: Text(
            '联系人',
            style: _titleStyle,
          ),
          children: _contacts.map((ContactInfoModel contact) {
            return Container(
              height: 40,
              color: Colors.white,
              child: Row(
                children: <Widget>[
                  Padding(
                      padding: EdgeInsets.only(left: AppScreen.setWidth(20))),
                  Expanded(
                    child: Text(
                      '${contact.name}${contact.position != null ? '-${contact.position}' : ''}' ??
                          '',
                      style: _contactInfoTextStyle,
                      overflow: TextOverflow.ellipsis,
                      maxLines: 1,
                    ),
                  ),
                  Container(
                    width: AppScreen.setWidth(120),
                    child: Text(
                      contact.phone ?? '',
                      style: _contactInfoTextStyle,
                      overflow: TextOverflow.ellipsis,
                      maxLines: 1,
                    ),
                  ),
                  Container(
                    width: 18,
                    height: 18,
                    child: ClipRRect(
                      borderRadius: BorderRadius.circular(9),
                      child: MaterialButton(
                        onPressed: () {
                          print('短信');
                        },
                        child: Image.asset(
                          'images/bt_order_talk.png',
                          fit: BoxFit.fill,
                        ),
                        padding: EdgeInsets.all(0),
                      ),
                    ),
                  ),
                  Padding(padding: EdgeInsets.only(right: 25)),
                  Container(
                    width: 18,
                    height: 18,
                    decoration: BoxDecoration(
                      color: Color(0xFF00BE98),
                      borderRadius: BorderRadius.circular(9),
                    ),
                    child: ClipRRect(
                      borderRadius: BorderRadius.circular(9),
                      child: MaterialButton(
                        onPressed: () {
                          print('电话');
                        },
                        child: Image.asset(
                          'images/bt_order_talk.png',
                          fit: BoxFit.fill,
                        ),
                        padding: EdgeInsets.all(0),
                      ),
                    ),
                  ),
                  Padding(padding: EdgeInsets.only(right: 25)),
                ],
              ),
            );
          }).toList(),
        ),
        _divider,
        TextExpansionTile(
          title: Text(
            '负责人',
            style: _titleStyle,
          ),
//          children: _principals.map((PrincipalInfoModel principal){
//            return Container(
//              height: 40,
//              color: Colors.white,
//              child: Row(
//                children: <Widget>[
//                  Text(principal.principalCreateEmployeeId ?? ''),
//                ],
//              ),
//            );
//          }).toList(),
        ),
        _divider,
      ],
    );
  }
}
